package com.wonders.service.impl;

import com.wonders.po.Book;
import com.wonders.service.BookService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service("bkService")
public class BookServiceImpl implements BookService {

    @Cacheable(value = {"books"}, key = "#isbn")
    public Book findBook(String isbn, String name) {
        System.out.println("findBook[isbn:" + isbn + ",name:" + name + "]");
        return new Book(isbn, name);
    }

    @CachePut(cacheNames = "books", key = "#isbn")
    public Book updateBook(String isbn, String name) {
        System.out.println("updateBook[isbn:" + isbn + ",name:" + name + "]");
        return new Book(isbn, name);
    }

    @CacheEvict(cacheNames = "books", allEntries = true)
    public void loadBooks() {
        System.out.println("loadBooks");
    }
}
